import { DynamicModule, Module } from "@nestjs/common";
import { EtcdService } from "./etcd.service";

@Module({
  providers: [EtcdService],
  exports: [EtcdService],
})
export class EtcdModule {
  static register(serviceName: string): DynamicModule {
    return {
      module: EtcdModule,
      providers: [
        {
          provide: EtcdService,
          useFactory: (serviceName) => new EtcdService(serviceName),
          inject: ["SERVICE_NAME"],
        },
        {
          provide: "SERVICE_NAME",
          useValue: serviceName,
        },
      ],
      exports: [EtcdService],
    };
  }
}
